﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using DataTransfer;
using BUS;
namespace Gui
{
    public partial class frmQuiDinh : Form
    {
        public QuiDinhBus qdBus = new QuiDinhBus();
        public frmQuiDinh()
        {
            InitializeComponent();
        }

       
        private void loadData()
        {
            dgvQuiDinh.DataSource = qdBus.GetAll();
            //dgvQuiDinh.Columns["ID"].Visible = false;
        }
        private void btnInsert_Click(object sender, EventArgs e)
        {
            QuiDinh qd = new QuiDinh();
            qd.QD = "TienChich";
            qd.Value = 20000;
            qdBus.Insert(qd);
            MessageBox.Show("Insert Success");
            loadData();

        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            QuiDinhBus.db.Dispose();
            this.Close();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            int index = dgvQuiDinh.CurrentRow.Index;
            if (index > 0)
            {
                QuiDinh qd = new QuiDinh();
                qd.ID = Convert.ToInt32(dgvQuiDinh["ID", index].Value.ToString());
                qdBus.Delele(qd.ID);
                MessageBox.Show("Delete Success");
                loadData();
            }
            else
            {
                MessageBox.Show("Chua chon iTem");
            }

        }
        private bool getItem(ref QuiDinh qd)
        {
            bool flag = false;
            int index = dgvQuiDinh.CurrentRow.Index;
            if (index > 0)
            {

                qd.ID = Convert.ToInt32(dgvQuiDinh["ID", index].Value.ToString());
              
                flag = true;
            }
            return flag;
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            QuiDinh qd = new QuiDinh();
            if (getItem(ref qd))
            {
                qd.CreateDate = DateTime.Now;
                qd.ModifyDate = DateTime.Now;
                qdBus.Update(qd);
                MessageBox.Show("update Succcess");
                loadData();
            }
            else
            {
                MessageBox.Show("Chua chin item");
            }

        }

        private void frmQuiDinh_Load(object sender, EventArgs e)
        {
            loadData();

        }
          
        

       




    }
}
